// pages/login/login.js
var app = getApp(); //获取应用实例
const pathLevel = '../../../'; //路径层级
const quote = require(pathLevel + 'utils/quote.config.js') //统一引入文件
const mta = quote.mta;
const util = quote.util;
const tools = quote.tools;
const api = quote.api;
const path = quote.paths;
const LoginRegist = quote.LoginRegist;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        path: path,
        Phone: "",
        verification: null,
        Pwd: "",
        Url: "",
        hiddenPwd: true,
        hiddenPhone: true,
        hiddenPhonecode: true,
        fromPage: null,
        goback: false,
        show_cn: false,
        show: true,
        code_cn: true,
        code: false,
        Phonecode: '',
        has_get_authCode: false,
        authCodeGetTime: 0,
        currentTab: 0,
        aaa: -4,
    },
    //nav导航切换
    swichNav: function(e) {
        // console.log(e)
        var curType = e.currentTarget.dataset.current;
        this.data.currentTab = curType
        if (this.data.currentTab == 1) {
            this.setData({
                currentTab: curType,
                show_cn: true,
                show: false,
                code: true,
                code_cn: false
            });
        } else if (this.data.currentTab == 0) {
            this.setData({
                currentTab: curType,
                show_cn: false,
                show: true,
                code: false,
                code_cn: true,
            })

        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

        console.log('打开登录页获取到的数据', options)

        this.setData({
            fromPage: options.fromPage || "",
            // goback: options.goback,
        })
    },
    onReady: function() {
        var that = this;

        LoginRegist.addParam(that, app, api, path);
        mta.Page.init();
    },
    //获取输入
    bindInput: function(e) {

        LoginRegist.bindInput(e);
    },

    aldClickRegist: function(e) {
        app.aldstat.sendEvent('登录-点击去注册');
        mta.Event.stat("sign_clickregister", {});
    },
    //账号密码登录
    tapLogin: function() {
        var self = this;

        app.aldstat.sendEvent('登录-点击去注册', {
            '微信openid': app.globalData.openId,
        });
        mta.Event.stat("sign_clickregister", { 'openid': app.globalData.openId, })

        LoginRegist.login(function(res) {
            app.aldstat.sendEvent('登录-登陆成功', {
                '微信openid': app.globalData.openId,
            });
            mta.Event.stat("sign_clickloginsuccess", { 'openid': app.globalData.openId, })
        })

    },
    //短信验证码登录
    tapLoginCode: function() {
        var that = this;
        console.log(that.data)

        app.aldstat.sendEvent('登录-点击去注册', {
            '微信openid': app.globalData.openId,
        });
        mta.Event.stat("sign_clickregister", { 'openid': app.globalData.openId, })

        LoginRegist.login_Code(function() {
            app.aldstat.sendEvent('登录-登陆成功', {
                '微信openid': app.globalData.openId,
            });
            mta.Event.stat("sign_clickloginsuccess", { 'openid': app.globalData.openId, })
        })

    },
    //失去焦点
    bindblur: function(e) {
        var self = this

        LoginRegist.bindblur(e);
    },
    //获取焦点
    bindfocus: function(e) {
        console.log(e)
        var self = this

        LoginRegist.bindfocus(e);
    },
    //发送验证码登录
    getAuthCode: function() {
        var that = this;

        app.aldstat.sendEvent('登录-点击发送验证码', {
            '微信openid': app.globalData.openId,
        });
        mta.Event.stat("register_sendverificationcode", { 'openid': app.globalData.openId, })

        LoginRegist.getAuthCode_login();
    },
    //点击获取验证码
    tapGetAuthCode: function(e) {
        var that = this;

        LoginRegist.tapGetAuthCode(e, 'login');
    },
})